<template>
  <page-body>
    <view class="page">
      <view class="flex benben-position-layout flex flex-wrap align-center addappointment_flex_0"
        :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
        <view class='flex flex-wrap align-center justify-between flex-sub addappointment_fd0_0'>
          <view class='flex flex-wrap align-center addappointment_fd0_0_c0' @tap.stop="handleJumpDiy" data-type="back"
            data-url="1">
            <text class='fu-iconfont2  addappointment_fd0_0_c0_c0'>&#xE794;</text>
          </view>
          <view class='flex flex-wrap align-stretch justify-center'>
            <text class='addappointment_fd0_0_c1_c0'>添加预约</text>
          </view>
          <view class='flex flex-wrap align-center justify-end addappointment_fd0_0_c0'>
          </view>
        </view>

      </view>
      <view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
      <!---flex布局flex布局开始-->
      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout">
        <view class='flex flex-wrap align-center justify-between addappointment_fd1_0' @tap.stop="goChooseCur"
          data-type="navigateTo" :data-url="`/pages/grzx/chooseCur/chooseCur`" v-if="!customerinfo">
          <view class='flex flex-wrap align-center'>
            <image class='addappointment_fd1_0_c0_c0' mode="aspectFit" :src='STATIC_URL+"165.png"'></image>
            <text class='addappointment_fd1_0_c0_c1'>*</text>
            <text>选择客户</text>
          </view>
          <view class='flex flex-wrap align-center'>
            <image class='addappointment_fd1_0_c1_c0' mode="aspectFit" :src='STATIC_URL+"11.png"'></image>
          </view>
        </view>


        <!-- 客户信息 -->
        <view class="container-box" v-if="customerinfo" @tap.stop="goChooseCur" data-type="navigateTo"
          :data-url="`/pages/grzx/chooseCur/chooseCur`">
          <view class="text-lg text-weight-600 flex align-center">
            <view>{{customerinfo.customer_name}}</view>
            <view class="margin-left-sm">{{customerinfo.customer_phone}}</view>
          </view>
          <view class="text-lg margin-top-sm flex align-center">
            <view>{{customerinfo.customer_type_name}}日期：</view>
            <view class="margin-top-xs" style="color: #E4C391;">{{customerinfo.date_time}}</view>
          </view>
        </view>
        <!-- end -->
        <view class='flex flex-wrap align-center justify-between addappointment_fd1_0'
          @tap.stop="pickerDiy1719297142345=true" v-if="!fittingroom_name">
          <view class='flex flex-wrap align-center'>
            <image class='addappointment_fd1_0_c0_c0' mode="aspectFit" :src='STATIC_URL+"166.png"'></image>
            <text class='addappointment_fd1_0_c0_c1'>*</text>
            <text>选择试衣间</text>
          </view>
          <view class='flex flex-wrap align-center'>
            <image class='addappointment_fd1_0_c1_c0' mode="aspectFit" :src='STATIC_URL+"11.png"'></image>
          </view>
        </view>
        <view class="addappointment_fd1_0_box" v-if="fittingroom_name">
          <view class='flex flex-wrap align-center justify-between addappointment_fd1_0_cc'
            @tap.stop="pickerDiy1719297142345=true">
            <view class='flex flex-wrap align-center'>
              <image class='addappointment_fd1_0_c0_c0' mode="aspectFit" :src='STATIC_URL+"170.png"'></image>
              <!-- <text class='addappointment_fd1_0_c0_c1'>*</text> -->
              <text>{{fittingroom_name|| '请选择试衣间'}}</text>
            </view>
            <view class='flex flex-wrap align-center'>
              <image class='addappointment_fd1_0_c1_c0' mode="aspectFit" :src='STATIC_URL+"11.png"'></image>
            </view>
          </view>
          <view class='flex flex-wrap align-center justify-between addappointment_fd1_0_cc'
            @tap.stop="pickerDiy1719212019101=true">
            <view class='flex flex-wrap align-center'>
              <image class='addappointment_fd1_0_c0_c0' mode="aspectFit" :src='STATIC_URL+"169.png"'></image>
              <!-- <text class='addappointment_fd1_0_c0_c1'>*</text> -->
              <text>{{appointment_date|| '请选择日期'}}</text>
            </view>
            <view class='flex flex-wrap align-center'>
              <image class='addappointment_fd1_0_c1_c0' mode="aspectFit" :src='STATIC_URL+"11.png"'></image>
            </view>
          </view>
          <view class='flex flex-wrap align-center'
            :class="period==1 ? 'addappointment_fd1_0_cc' : 'addappointment_fd1_0_ccf'">
            <view class='flex flex-wrap align-center'>
              <image class='addappointment_fd1_0_c0_c0' mode="aspectFit" :src='STATIC_URL+"171.png"'></image>
            </view>
            <view class="flex align-center">
              <view v-for="(item,index) in chooseArr" :key="index"
                class="flex align-center text-df text-333 margin-right-lg">
                <view>{{item.name}}</view>
                <view class="radius" :class="period==item.value ? 'active' :''"></view>
              </view>
            </view>

          </view>
          <view class="flex align-center flex-wrap padding-bottom-sm" v-if="period==2">
            <view v-for="(item,index) in timeList" :key="index" class="text-sm arrArr" @click.stop="chooseTime(item)"
              :class="item.value==time_period ? 'active' : ''">
              {{item.name}}
            </view>
          </view>
          <!-- @click.stop="isTime=true" -->
          <view class='flex flex-wrap align-center justify-between addappointment_fd1_0_cc'
            style="border-top: 1rpx solid #EEEEEE;border-bottom: none;">
            <view class='flex flex-wrap align-center'>
              <image class='addappointment_fd1_0_c0_c0' mode="aspectFit" :src='STATIC_URL+"171.png"'></image>
              <!-- <text class='addappointment_fd1_0_c0_c1'>*</text> -->
              <!-- <text>{{time_str|| '请选择时间点'}}</text> -->
              <input type="text" maxlength="-1" class="text-333 text-df input-box" v-model='time_str'
                placeholder="请输入时间点" />
            </view>
            <!-- <view class='flex flex-wrap align-center'>
              <image class='addappointment_fd1_0_c1_c0' mode="aspectFit" :src='STATIC_URL+"11.png"'></image>
            </view> -->
          </view>
        </view>

      </view>

      <!---flex布局flex布局结束-->
      <view class="flex benben-position-layout flex flex-wrap align-center addappointment_flex_2" @click.stop="submit">
        <button class='addappointment_fd2_0'>确定</button>

      </view>
      <view :style="{height: '88rpx'}"></view>
      <!--选择器开始 -->
      <benben-picker ref="benbenWritePickerCodepicker3" :visible.sync="pickerDiy1719297142345"
        :label.sync='fittingroom_name' :value.sync='fittingroom_id' :options='list' mode='selector' :mask-show='true'
        :timeout='true' :picker-height='88' default-type='aid' :default-props='{"label":"name","value":"aid"}'>
        <template #picker-header>
          <view class='flex flex-wrap align-center justify-between addappointment_picker3_0'>
            <text @tap="$refs.benbenWritePickerCodepicker3.cancel()">取消</text>
            <text>选择试衣间</text>
            <text class='addappointment_picker3_0_c2'
              @tap="$refs.benbenWritePickerCodepicker3.pickerConfirm()">确认</text>
          </view>
        </template>
      </benben-picker>
      <!--选择器结束 -->
      <!--时间选择开始 -->
      <benben-picker ref="benbenWritePickerCodepicker4" :visible.sync="pickerDiy1719212019101"
        :value.sync='appointment_date' mode='date' :picker-height='88' :current='true' :mask-show='true' fields='day'
        :timeout='true' start-year='现在' end-year='2050-12-31'>
        <template #picker-header>
          <view class='flex flex-wrap align-center justify-between addappointment_picker3_0'>
            <text @tap="$refs.benbenWritePickerCodepicker4.cancel()">取消</text>
            <text>选择日期</text>
            <text class='addappointment_picker3_0_c2'
              @tap="$refs.benbenWritePickerCodepicker4.pickerConfirm()">确认</text>
          </view>
        </template>
      </benben-picker>
      <!--时间选择结束 -->
      <!--时间点选择开始 -->
      <benben-picker ref="benbenWritePickerCodepicker5" :visible.sync="isTime" :value.sync='time_str1' mode='time'
        :picker-height='88' :current='true' :disabled-after="true" :second="false" :mask-show='true' :timeout='true'
        start-year='现在' end-year='2050-12-31'>
        <template #picker-header>
          <view class='flex flex-wrap align-center justify-between addappointment_picker3_0'>
            <text @tap="$refs.benbenWritePickerCodepicker5.cancel()">取消</text>
            <text>选择</text>
            <text class='addappointment_picker3_0_c2' @tap="cancelTime()">确认</text>
          </view>
        </template>
      </benben-picker>
      <!--时间点选择开始 -->
    </view>
  </page-body>
</template>
<script>
  export default {
    components: {},


    data() {
      return {
        isTime: false,
        pickerDiy1719212019101: false,
        "pickerDiy1719297142345": false,
        list: [],
        appointment_date: '', //预约日期
        time_period: '', //预约时间段
        time_str: '', //时间点
        customerinfo_id: '', //客户信
        fittingroom_id: '', //试衣间管理ID
        fittingroom_name: '',
        customerinfo: null,
        chooseArr: [{
            name: '未选中',
            value: '1'
          },
          {
            name: '选中',
            value: '2'
          },
        ],
        period: '2',
        timeList: [],
        time_str1: '',
        aid: ''
      };
    },
    computed: {

    },
    watch: {},
    onLoad(options) {
      let {
        aid
      } = options
      if (aid !== undefined) this.aid = aid
      if (this.aid) {
        this.getDetail()
      }

      this.getList()
    },
    onUnload() {

    },
    onReady() {

    },
    onShow() {
      uni.$on('custoerm', data => {
        this.customerinfo = data
        console.log('data', data)
      })
    },
    onHide() {

    },
    onResize() {

    },
    onPullDownRefresh() {

    },
    onReachBottom(e) {

    },
    onPageScroll(e) {

    },
    methods: {
      goChooseCur() {
        if (this.aid) {
          return
        }
        uni.navigateTo({
          url: `/pages/grzx/chooseCur/chooseCur`
        })
      },
      getDetail() {
        this.$api.post(global.apiUrls.post6698c4ff852b9, {
          aid: this.aid
        }).then(res => {
          if (res.data.code == 1) {
            this.appointment_date = res.data.data.appointment_date
            this.customerinfo = {
              aid: res.data.data.customerinfo_id,
              customer_name: res.data.data.customer_name,
              customer_phone: res.data.data.customer_phone,
              customer_type_name: res.data.data.customer_type_name,
              date_time: res.data.data.date_time
            }
            this.fittingroom_name = res.data.data.fittingroom_name
            this.fittingroom_id = res.data.data.fittingroom_id
            this.time_period = res.data.data.time_period
            this.time_str = res.data.data.time_str
          }
        })
      },
      cancelTime() {
        console.log('ppp', this.time_str1)
        if (this.time_str1) {
          let arr = this.time_str1.split(':')
          this.time_str = arr[0] + ':' + arr[1]
          console.log(this.time_str)
        }


        this.$refs.benbenWritePickerCodepicker5.pickerConfirm()
      },
      chooseTime(item) {
        console.log('item')
        this.time_period = item.value
      },
      choosetime_period(item) {
        this.period = item.value
      },
      getList() {
        this.$api.post(global.apiUrls.post666cf0f0a6820).then(res => {
          if (res.data.code == 1) {
            this.list = res.data.data
          }
        })
        this.$api.post(global.apiUrls.post666d0c77bd9af).then(res => {
          if (res.data.code == 1) {
            this.timeList = res.data.data.time_period
          }
        })
      },
      submit() {
        if (this.customerinfo == null) {
          this.$message.info('请选择客户')
          return;
        }
        if (!this.fittingroom_id) {
          this.$message.info('请选择试衣间')
          return;
        }
        if (!this.appointment_date) {
          this.$message.info('请选择日期')
          return;
        }
        if (!this.time_period) {
          this.$message.info('请选择时间段')
          return;
        }
        // if (!this.time_str) {
        //   this.$message.info('请选择时间点')
        //   return;
        // }
        this.$api.post(global.apiUrls.post666cf49be1371, {
          customerinfo_id: this.customerinfo.aid,
          fittingroom_id: this.fittingroom_id,
          time_period: this.time_period,
          time_str: this.time_str,
          appointment_date: this.appointment_date,
          aid: this.aid

        }).then(res => {
          if (res.data.code == 1) {
            this.$message.info('预约成功')
            uni.switchTab({
              url: `/pages/tabBar/home/home`
            })
          } else {
            this.$message.info(res.data.msg)
          }
        })
      },
    }
  };
</script>
<style lang="scss" scoped>
  .radius {
    width: 16rpx;
    height: 16rpx;
    border-radius: 50%;
    background-color: #EEEEEE;
    margin-left: 16rpx;

    &.active {
      background: #E4C391;

    }
  }

  .arrArr {
    width: 264rpx;
    height: 56rpx;
    background: #EEEEEE;
    border-radius: 16rpx;
    text-align: center;
    line-height: 56rpx;
    color: #333333;
    margin-right: 24rpx;
    margin-top: 24rpx;

    &.active {
      background: #E4C391;
      color: #FFFFFF;
    }
  }

  .addappointment_fd1_0_box {
    width: 686rpx;
    background-color: #FFFFFF;
    border-radius: 16rpx;
    margin: 0 auto;
    padding: 0 32rpx;
    margin: 24rpx auto 24rpx auto;
  }

  .addappointment_fd1_0_ccs {
    padding: 32rpx;
  }

  .addappointment_fd1_0_cc {
    height: 120rpx;
    line-height: 120rpx;
    border-bottom: 1rpx solid #EEEEEE;
  }

  .addappointment_fd1_0_ccf {
    height: 120rpx;
    line-height: 120rpx;
    border-bottom: 1rpx solid #EEEEEE;
  }

  .container-box {
    padding: 32rpx;
    border-radius: 16rpx;
    background-color: #FFFFFF;
    width: 686rpx;
    margin: 24rpx auto 0 auto;
  }

  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: #F8F8F8;
    background-size: 100% auto;
  }

  .addappointment_flex_0 {
    background: #fff;
    width: 750rpx;
    height: 88rpx;
    overflow: hidden;
    z-index: 10;
    top: 0rpx;
    background-size: 100% auto !important;
  }

  .addappointment_fd0_0_c1_c0 {
    font-size: 36rpx;
    font-weight: 700;
    color: #333333;
    line-height: 50rpx;
  }

  .addappointment_fd0_0_c0_c0 {
    font-size: 36rpx;
    color: #333;
  }

  .addappointment_fd0_0_c0 {
    width: 120rpx;
  }

  .addappointment_fd0_0 {
    padding: 0rpx 32rpx 0rpx 32rpx;
  }

  .addappointment_fd1_0_c1_c0 {
    width: 14rpx;
    height: 26rpx;
  }

  .addappointment_fd1_0_c0_c1 {
    color: var(--benbenFontColor5);
  }

  .addappointment_fd1_0_c0_c0 {
    width: 36rpx;
    height: 36rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    margin: 0rpx 24rpx 0rpx 0rpx;
  }

  .input-box {}

  .addappointment_fd1_0 {
    background: #FFFFFF;
    border-radius: 24rpx;
    width: 686rpx;
    height: 120rpx;
    line-height: 120rpx;
    margin: 24rpx auto 0rpx auto;
    padding: 0rpx 24rpx 0rpx 24rpx;
  }

  .addappointment_flex_2 {
    width: 686rpx;
    height: 88rpx;
    overflow: hidden;
    z-index: 10;
    bottom: calc(40rpx + var(--window-bottom));
    left: 32rpx;
  }

  .addappointment_fd2_0 {
    background: #F9E4C3;
    border-radius: 44rpx 44rpx 44rpx 44rpx;
    width: 686rpx;
    line-height: 88rpx;
    font-size: 28rpx;
    color: var(--benbenFontColor0);
    height: 88rpx;
  }

  .addappointment_picker3_0_c2 {
    color: #F9E4C3;
  }

  .addappointment_picker3_0 {
    border-bottom: 1px solid #eee;
    background: #fff;
    padding: 0rpx 32rpx 0rpx 32rpx;
    line-height: 88rpx;
    border-radius: 25rpx 25rpx 0rpx 0rpx;
    background-size: 100% auto !important;
  }
</style>
